home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 April / PCWorld_2008-04_cd.bin / v cisle / ozo / zotero-1.0.3.xpi / components / zotero-service.js < prev   
Text File  |  2007-07-31  |  7KB  |  234 lines

  1. const ZOTERO_CONTRACTID = '@zotero.org/Zotero;1';
  2. const ZOTERO_CLASSNAME = 'Zotero';
  3. const ZOTERO_CID = Components.ID('{e4c61080-ec2d-11da-8ad9-0800200c9a66}');
  4. const ZOTERO_IID = Components.interfaces.chnmIZoteroService; //unused
  5.  
  6. const Cc = Components.classes;
  7. const Ci = Components.interfaces;
  8.  
  9. // Assign the global scope to a variable to passed via wrappedJSObject
  10. var ZoteroWrapped = this;
  11.  
  12.  
  13. /********************************************************************
  14. * Include the core objects to be stored within XPCOM
  15. *********************************************************************/
  16.  
  17. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  18.     .getService(Ci.mozIJSSubScriptLoader)
  19.     .loadSubScript("chrome://zotero/content/xpcom/zotero.js");
  20.  
  21. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  22.     .getService(Ci.mozIJSSubScriptLoader)
  23.     .loadSubScript("chrome://zotero/content/xpcom/db.js");
  24.  
  25. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  26.     .getService(Ci.mozIJSSubScriptLoader)
  27.     .loadSubScript("chrome://zotero/content/xpcom/schema.js");
  28.  
  29. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  30.     .getService(Ci.mozIJSSubScriptLoader)
  31.     .loadSubScript("chrome://zotero/content/xpcom/data_access.js");
  32.  
  33. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  34.     .getService(Ci.mozIJSSubScriptLoader)
  35.     .loadSubScript("chrome://zotero/content/xpcom/attachments.js");
  36.  
  37. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  38.     .getService(Ci.mozIJSSubScriptLoader)
  39.     .loadSubScript("chrome://zotero/content/xpcom/notifier.js");
  40.  
  41. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  42.     .getService(Ci.mozIJSSubScriptLoader)
  43.     .loadSubScript("chrome://zotero/content/xpcom/history.js");
  44.  
  45. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  46.     .getService(Ci.mozIJSSubScriptLoader)
  47.     .loadSubScript("chrome://zotero/content/xpcom/search.js");
  48.  
  49. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  50.     .getService(Ci.mozIJSSubScriptLoader)
  51.     .loadSubScript("chrome://zotero/content/xpcom/ingester.js");
  52.     
  53. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  54.     .getService(Ci.mozIJSSubScriptLoader)
  55.     .loadSubScript("chrome://zotero/content/xpcom/translate.js");
  56.     
  57. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  58.     .getService(Ci.mozIJSSubScriptLoader)
  59.     .loadSubScript("chrome://zotero/content/xpcom/cite.js");
  60.     
  61. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  62.     .getService(Ci.mozIJSSubScriptLoader)
  63.     .loadSubScript("chrome://zotero/content/xpcom/cite_compat.js");
  64.     
  65. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  66.     .getService(Ci.mozIJSSubScriptLoader)
  67.     .loadSubScript("chrome://zotero/content/xpcom/quickCopy.js");
  68.  
  69. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  70.     .getService(Ci.mozIJSSubScriptLoader)
  71.     .loadSubScript("chrome://zotero/content/xpcom/report.js");
  72.  
  73. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  74.     .getService(Ci.mozIJSSubScriptLoader)
  75.     .loadSubScript("chrome://zotero/content/xpcom/timeline.js");
  76.     
  77. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  78.     .getService(Ci.mozIJSSubScriptLoader)
  79.     .loadSubScript("chrome://zotero/content/xpcom/utilities.js");
  80.  
  81. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  82.     .getService(Ci.mozIJSSubScriptLoader)
  83.     .loadSubScript("chrome://zotero/content/xpcom/integration.js");
  84.  
  85. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  86.     .getService(Ci.mozIJSSubScriptLoader)
  87.     .loadSubScript("chrome://zotero/content/xpcom/file.js");
  88.  
  89. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  90.     .getService(Ci.mozIJSSubScriptLoader)
  91.     .loadSubScript("chrome://zotero/content/xpcom/fulltext.js");
  92.  
  93. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  94.     .getService(Ci.mozIJSSubScriptLoader)
  95.     .loadSubScript("chrome://zotero/content/xpcom/mime.js");
  96.  
  97. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  98.     .getService(Ci.mozIJSSubScriptLoader)
  99.     .loadSubScript("chrome://zotero/content/xpcom/itemTreeView.js");
  100.  
  101. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  102.     .getService(Ci.mozIJSSubScriptLoader)
  103.     .loadSubScript("chrome://zotero/content/xpcom/collectionTreeView.js");
  104.  
  105. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  106.     .getService(Ci.mozIJSSubScriptLoader)
  107.     .loadSubScript("chrome://zotero/content/xpcom/progressWindow.js");
  108.  
  109. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  110.     .getService(Ci.mozIJSSubScriptLoader)
  111.     .loadSubScript("chrome://zotero/content/xpcom/annotate.js");
  112.  
  113. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  114.     .getService(Ci.mozIJSSubScriptLoader)
  115.     .loadSubScript("chrome://global/content/nsTransferable.js");
  116.  
  117. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  118.     .getService(Ci.mozIJSSubScriptLoader)
  119.     .loadSubScript("chrome://global/content/nsDragAndDrop.js");
  120.  
  121. /********************************************************************/
  122.  
  123.  
  124. // Initialize the Zotero service
  125. //
  126. // This runs when ZoteroService is first requested.
  127. // Calls to other XPCOM components must be in here rather than in top-level
  128. // code, as other components may not have yet been initialized.
  129. function setupService(){
  130.     Zotero.init();
  131. }
  132.  
  133. function ZoteroService(){
  134.     this.wrappedJSObject = ZoteroWrapped.Zotero;
  135.     setupService();
  136. }
  137.  
  138.  
  139. /**
  140. * Convenience method to replicate window.alert()
  141. **/
  142. function alert(msg){
  143.     Cc["@mozilla.org/embedcomp/prompt-service;1"]
  144.         .getService(Ci.nsIPromptService)
  145.         .alert(null, "", msg);
  146. }
  147.  
  148. /**
  149. * Convenience method to replicate window.confirm()
  150. **/
  151. function confirm(msg){
  152.     return Cc["@mozilla.org/embedcomp/prompt-service;1"]
  153.         .getService(Ci.nsIPromptService)
  154.         .confirm(null, "", msg);
  155. }
  156.  
  157.  
  158. /**
  159. * Convenience method to replicate window.setTimeout()
  160. **/
  161. function setTimeout(func, ms){
  162.     var timer = Components.classes["@mozilla.org/timer;1"].
  163.         createInstance(Components.interfaces.nsITimer);
  164.     // {} implements nsITimerCallback
  165.     timer.initWithCallback({notify:func}, ms,
  166.         Components.interfaces.nsITimer.TYPE_ONE_SHOT);
  167. }
  168.  
  169.  
  170. //
  171. // XPCOM goop
  172. //
  173. ZoteroService.prototype = {
  174.     QueryInterface: function(iid){
  175.         if (!iid.equals(Components.interfaces.nsISupports) &&
  176.             !iid.equals(ZOTERO_IID)){ // interface unused
  177.             throw Components.results.NS_ERROR_NO_INTERFACE;
  178.         }
  179.         return this;
  180.     }
  181. };
  182.  
  183.  
  184. var ZoteroFactory = {
  185.     createInstance: function(outer, iid){
  186.         if (outer != null){
  187.             throw Components.results.NS_ERROR_NO_AGGREGATION;
  188.         }
  189.         return new ZoteroService().QueryInterface(iid);
  190.     }
  191. };
  192.  
  193.  
  194. var ZoteroModule = {
  195.     _firstTime: true,
  196.     
  197.     registerSelf: function(compMgr, fileSpec, location, type){
  198.         if (!this._firstTime){
  199.             throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  200.         }
  201.         this._firstTime = false;
  202.         
  203.         compMgr =
  204.             compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  205.         
  206.         compMgr.registerFactoryLocation(ZOTERO_CID,
  207.                                         ZOTERO_CLASSNAME,
  208.                                         ZOTERO_CONTRACTID,
  209.                                         fileSpec,
  210.                                         location,
  211.                                         type);
  212.     },
  213.     
  214.     unregisterSelf: function(compMgr, location, type){
  215.         compMgr =
  216.             compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  217.         compMgr.unregisterFactoryLocation(ZOTERO_CID, location);
  218.     },
  219.     
  220.     getClassObject: function(compMgr, cid, iid){
  221.         if (!cid.equals(ZOTERO_CID)){
  222.             throw Components.results.NS_ERROR_NO_INTERFACE;
  223.         }
  224.         if (!iid.equals(Components.interfaces.nsIFactory)){
  225.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  226.         }
  227.         return ZoteroFactory;
  228.     },
  229.     
  230.     canUnload: function(compMgr){ return true; }
  231. };
  232.  
  233. function NSGetModule(comMgr, fileSpec){ return ZoteroModule; }
  234.